package acm.pta14;

import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
import java.util.Scanner;

public class 均是素数 {
    static int n = 1000000;
    static BitSet bitSet = new BitSet(n);

    public static void main(String[] args) {
        List<Integer> prims = getPrims();
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int r = sc.nextInt();
        int s = 0, e = 0;
        for (int i = 0; i < prims.size(); i++) {
            if (prims.get(i) >= l) {
                s = i;
                break;
            }
        }
        for (int i = s; i < prims.size(); i++) {
            if (prims.get(i) > r) {
                e = i - 1;
                break;
            }
        }
        int res=0;
        for (int i = s; i <= e; i++) {
            for (int j = i + 1; j <= e; j++) {
                for (int k = j + 1; k <= e; k++) {
                    if (isPrim(prims.get(i) * prims.get(j) + prims.get(k))
                            && isPrim(prims.get(j) * prims.get(k) + prims.get(i))
                            && isPrim(prims.get(k) * prims.get(i) + prims.get(j))
                    ) {
                        res++;
                    }
                }
            }
        }
        System.out.println(res);
    }

    public static List<Integer> getPrims() {
        bitSet.set(0);
        bitSet.set(1);
        List<Integer> prims = new ArrayList<>();
        int cnt = 0;
        for (int i = 2; i <= n; i++) {
            if (!bitSet.get(i)) {
                prims.add(i);
            }
            for (int j = 0; prims.get(j) * i <= n; j++) {
                bitSet.set(prims.get(j) * i);
                if (i % prims.get(j) == 0) break;
            }
        }
        return prims;
    }

    public static boolean isPrim(int n) {
        return !bitSet.get(n);
    }
}
